<?php
class groupManager extends BaseModule{
    
    private $groupid;
	public function __construct($groupid =''){
		parent::__construct();
                $this->groupid=$groupid;
	}
	
        //添加用户组
	public function authgroup($username,$job){
            $root_text = $_POST['hobby'];
            if (isset($root_text)) {
                $root_txt = implode(",", $root_text);
            }else{
                Handler_tool::alertAndGoBack('请选择用户组权限！');
            }
            /******************************开始添加修改用户组***************************/
            $group_name = trim(Handler_http::getPOST('nickname'));
            if (!preg_match("/^[\x{4e00}-\x{9fa5}]+$/u", $group_name)) {
                Handler_tool::alertAndGoBack('请输入中文组名！');
            }
            if(!empty($job)){
                $group = ManagingModule::update_group($group_name, $root_txt, $this->groupid);
   
                if ($group) {
                    Handler_tool::alertAndRedirect('修改成功', '/managing/groupList/');
                } else {
                    Handler_tool::alertAndRedirect('修改失败', '/managing/userGroup/?groupid='.$this->groupid);
                }
            }else{
                $group = ManagingModule::add_group($group_name, $root_txt, $username);
                if ($group) {
                Handler_tool::alertAndRedirect('添加成功', '/managing/groupList/');
                } else {
                    Handler_tool::alertAndRedirect('添加失败', '/managing/userGroup/');
                }
            }
            
	}

}